package org.itstack.demo.netty.server;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.protobuf.ProtobufDecoder;
import io.netty.handler.codec.protobuf.ProtobufEncoder;
import io.netty.handler.codec.protobuf.ProtobufVarint32FrameDecoder;
import io.netty.handler.codec.protobuf.ProtobufVarint32LengthFieldPrepender;
import org.itstack.demo.netty.domain.MsgBody;

public class MyChannelInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        socketChannel.pipeline().addLast(new ProtobufVarint32FrameDecoder());

        socketChannel.pipeline().addLast(new ProtobufDecoder(MsgBody.getDefaultInstance()));

        socketChannel.pipeline().addLast(new ProtobufEncoder());

        socketChannel.pipeline().addLast(new ProtobufVarint32LengthFieldPrepender());

        socketChannel.pipeline().addLast(new MyServerHandler());
    }
}
